package com.haoma.controller;

import com.haoma.entity.Website;
import com.haoma.result.Result;
import com.haoma.service.WebsiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * Description:
 */
@RestController
@RequestMapping("/admin/website")
public class WebsiteController {

    @Autowired
    private WebsiteService websiteService;


    /**
     * 获取网站的个人信息
     *
     * @return
     */
    @GetMapping
    public Result getWebsite() {
        Website website = websiteService.getWebsite();
        return Result.success(website);
    }

    /**
     * 修改网站信息
     *
     * @param website
     * @return
     */
    @PutMapping("/update")
    public Result updateWebsite(@RequestBody Website website) {
        websiteService.updateWebsite(website);
        return Result.success();
    }

    /**
     * 上传url
     *
     * @param multipartFile
     * @return
     */
    @PostMapping("/fileUpload/{type}")
    public Result fileUpload(@PathVariable Integer type, @RequestParam("file") MultipartFile multipartFile) {
        String url = websiteService.fileUpload(type,multipartFile);
        return Result.success(url);
    }
}
